home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / samples / ooftst02.inc < prev    next >
Encoding:
Text File  |  1995-09-27  |  2.0 KB  |  93 lines  |  [TEXT/CWIE]

  1. // included in ooftest2, 3 & 4
  2.  
  3. REF_TABLE(dbPeople)
  4. SET_TABLE(dbVisits)
  5.  
  6. CLASS_TABLE(dbPeople)
  7.     dbChar        LastName, Othernames;
  8.     dbVisitsSet    Visits;
  9.     dbLong        PatientNo;
  10.     dbLong        Salary;
  11.  
  12.     dbPeople() :
  13.                 dbTable("People"),
  14.                 LastName(40, "Last Name", kIndexed),
  15.                 Othernames(80, "Other names", kIndexed),
  16.                 PatientNo("PatientNo", kIndexNoDups),
  17.                 Salary("Salary", kIndexed)
  18.     {};
  19.     
  20. // my own data entry procedures
  21.     void Add(const char *lname, const char *oname, const long salary);
  22.     void AddVisit(const char* visitDate, const char* why);
  23.     void AddTest2Data();
  24.     
  25. };
  26.  
  27.  
  28. CLASS_TABLE(dbVisits)
  29.     dbPeopleRef    Person;
  30.     dbLong        PatientNo;
  31.     dbDate        VisitDate;
  32.     dbText        Why;
  33.     dbVisits() : 
  34.                 dbTable("Visits"),
  35.                 PatientNo("PatientNo", kIndexed),
  36.                 VisitDate("VisitDate", kIndexed),
  37.                 Why("Reason for Visit")
  38.             {};
  39. };
  40.  
  41.  
  42. void dbPeople::Add(const char *lname, const char *oname, const long salary)
  43. {
  44.     newRecord();
  45.     LastName = lname;
  46.     Othernames = oname;
  47.     Salary = salary;
  48.     PatientNo = sequenceNumber();
  49.     saveRecord();
  50. }
  51.  
  52.  
  53. void dbPeople::AddVisit(const char* visitDate, const char* why)
  54. {
  55.     Visits.newRecord();
  56.     Visits->VisitDate() = visitDate;
  57.     Visits->Why() = why;
  58. }
  59.  
  60.  
  61. void dbPeople::AddTest2Data()
  62. {
  63. // yes, if using SmartHeap debugging the following can take long enough to make folks wonder
  64. // there are a *lot* of places where OOFILE calls SmartHeap to check memory
  65.         cout << "Generating new test records..." << flush;
  66.         Add("Smith", "John", 20000);
  67.             AddVisit("1/10/1994", "Sore Knee");
  68.             AddVisit("14/10/1994", "Measles");
  69.         saveRecord();
  70.         
  71.         Add("DENT", "Trissa", 99999);
  72.             AddVisit("23-11-1994", "Flu");
  73.         saveRecord();
  74.  
  75.         Add("Dent", "Andy", 50000);
  76.             AddVisit("4.10.1994", "Flu");
  77.         saveRecord();
  78.  
  79.         Add("Taylor", "Ken", 75000);
  80.         cout << endl << endl;
  81. }
  82.  
  83.  
  84. // global variables that define the database using the above classes
  85.  
  86.     dbConnect_ctree    theDB;
  87.     dbPeople     People;
  88.     dbVisits    Visits;
  89.  
  90.   dbRelationship PatientVisits(People.Visits, Visits.Person, 
  91.                                People.PatientNo,     Visits.PatientNo);
  92.  
  93.